package com.yuhanginfo.modules.web.web;

import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import com.yuhanginfo.common.web.BaseController;
import com.yuhanginfo.modules.web.util.WebUserUtils;
import com.yuhanginfo.modules.web.entity.WebYongUser;
import com.yuhanginfo.modules.web.service.CustomerHistoryViewService;
import com.yuhanginfo.modules.web.service.GoodsListService;
import com.yuhanginfo.modules.web.service.WebClassService;

/**
 * 商品详情
 *
 */
@Controller
@RequestMapping(value = "${frontPath}/goodsDetail")
public class GoodsDetailController extends BaseController{
	
	@Autowired
	private GoodsListService goodsListService;
	@Autowired
	private WebClassService webClassService;
	@Autowired
	private CustomerHistoryViewService customerService;
	
	@RequestMapping(value = {"list", ""})
	public String list(String goodsCode,String storeCode,String useIp,HttpServletRequest request, HttpServletResponse response, Model model) {
		WebYongUser yongUser=WebUserUtils.getYongUser();
		//删除历史浏览表脏数据
		customerService.deleteRub();
		customerService.save(goodsCode,storeCode,useIp);
		model.addAttribute("user",yongUser);
		Map<String,String> params=new HashMap<String, String>();
		params.put("goodsCode", goodsCode);
		params.put("storeCode", storeCode);
		params.put("useIp", useIp);
		model.addAttribute("goodsDetail", goodsListService.getGoodsByCode(params));
		model.addAttribute("allClassesList",webClassService.getAllClasses());
		model.addAttribute("historyList",customerService.getHistoryGoodsByIp(useIp));
		return "modules/web/goodsDetail";
	}
	
}
